package com.bases {
	import com.font.FontTypeCustom;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;

	/**
	 * LinkButton:图片和文字的组合按钮
	 * @author pethan
	 *
	 */
	public class LinkButton extends TUIComponent {
		private var icon:Bitmap; //图标
		private var lblText:TLable; //文本文字
		private var smallData:BitmapData; //小图的数据
		private var bigData:BitmapData; //大图的数据
		private var oldColor:uint; //原始文本颜色
		private var overColor:uint; //鼠标划过去的颜色
		private var fontSize:int; //字体大小

		/**
		 * 初始化LinkButton
		 * @param smallBitmap  小图标数据
		 * @param bigBitmapData 鼠标划过去图标数据
		 * @param text  文本数据
		 * @param color  颜色值
		 * @param overColor  划过去的颜色值
		 *
		 */
		public function LinkButton(smallBitmap:BitmapData, bigBitmapData:BitmapData, text:String, size:int = 12, color:uint = 0x0, overColor:uint = 0x0){
			super();
			this.smallData = smallBitmap;
			this.bigData = bigBitmapData;
			this.oldColor = color;
			this.overColor = overColor;
			icon = new Bitmap(smallData);
			this.fontSize = size;
			this.lblText = new TLable();
			this.lblText.text = text;
			this.lblText.setTextFormat(new TextFormat(FontTypeCustom.SimHei, size, color));
			this.addChilds(icon, lblText);
			this.lblText.adateLabel();
			this.relayout();
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.useHandCursor = true;
			this.buttonMode = true;
		}

		override protected function relayout():void {
			super.relayout();
			this.lblText.setPos(this.icon.width + 2, 0);
		}

		private function onMouseOver(event:MouseEvent):void { /*鼠标划过去*/
			this.icon.bitmapData = this.bigData;
			this.lblText.setTextFormat(new TextFormat(FontTypeCustom.SimHei, fontSize, overColor));
			this.relayout();
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}

		private function onMouseOut(event:MouseEvent):void { /*鼠标划走*/
			this.icon.bitmapData = this.smallData;
			this.lblText.setTextFormat(new TextFormat(FontTypeCustom.SimHei, fontSize, oldColor));
			this.relayout();
			this.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
	}
}